### FOR FIGURE S13 IN SUPPLEMENTARY INFORMATION:

rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
#install.packages("extrafont")
library(extrafont)
#install.packages("performance")
library("performance")
library("see")
library("haven")

######### Binary Treatment -------
setwd("~/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Data")
setwd("/Users/sergimartinez/Dropbox/EUI/BET HOUSES PROJECT/data/estimates_050121/")

#Activate:
library(DRDID)
library(did)

## Data to use [This is the data used in the paper:]
allmap <- read_dta("gambling_data.dta")

out <- att_gt(yname="pau",
              tname="year",
              gname="tf",
              idname="school_id",
              data=allmap,
              bstrap=FALSE,
              cband=FALSE)

summary(out)

ggdid(out)

palette2 = c("red", "blue")

theme_results <- theme_bw(base_size = 8) +
  theme(text=element_text(family="Times",size = 16),
        axis.text.x = element_text(size = 14, color = "black"),
        axis.text.y = element_text(size = 14, color = "black"),
        axis.title.y = element_text(size = 16, color = "black"),
        axis.title.x = element_text(size = 16, color = "black"),
        legend.position = "bottom",
        legend.key = element_rect(fill = NA),
        legend.text = element_text(size = 16),
        legend.title = element_text(size = 8),
        strip.text.y.right = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        legend.background=element_blank(),
        strip.text.x = element_text(size=8))

es <- aggte(out, type = "dynamic")
figureS13 <- ggdid(es) +
  scale_colour_manual(name = "",values = palette2, labels = c("Before betting\nhouses openings", "After")) +
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black") +
  ylab("Effect of new betting houses opening at less\nthan 500m. on educational performance (0-10)") +
  xlab("Time periods") +
  theme_results +
  theme(panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
  )

figureS13
#ggsave("050121_santanna_120321.png", plot = santannaetal, width = 20, height = 15, units = "cm")

